//
//  ViewController.m
//  openshare框架实现第三方分享及登陆
//
//  Created by zxy on 2018/4/20.
//  Copyright © 2018年 zssh. All rights reserved.
//

#import "ViewController.h"
#import "OpenShareHeader.h"

#define weiboAppkey @"2746166174"
#define weiboAppSercet @"2638a395eec6e19396bf106c54a9c626"

#define qqAppID @"1106860795"
#define qqAppkey @"fnXj1eqKKxAcU0Lv"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

/**正常开放中，第三方登陆和分享，需先判断[OpenShare isQQInstalled]是否安装软件，
 如果没有，隐藏对应登陆和分享按钮。
 其中登陆：微博、QQ没有安装客户端也可以唤起网页页面，分享：则必须要安装客户端才能分享*/


/************************ openShare实现第三方分享 ****************************/

#pragma mark - 配置分享信息
- (OSMessage *)shareMessage {
    OSMessage *message = [[OSMessage alloc] init];
//    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
//    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
//    NSString *now = [fmt stringFromDate:[NSDate date]];
    message.title = [NSString stringWithFormat:@"大鸟的分享"];
    //微博分享此图片不会被展示，qq可以
    message.image = [UIImage imageNamed:@"114.png"];
    // 缩略图
    message.thumbnail = [UIImage imageNamed:@"icon-40.png"];
    //qq分享需要设置desc信息，不然调不起qq分享界面
    message.desc = [NSString stringWithFormat:@"大鸟的分享"];
    message.link=@"http://www.jianshu.com/users/e944bed06906/latest_articles";
    return message;
}


- (IBAction)weiboShare:(UIButton *)sender {
    
    OSMessage *msg = [self shareMessage];
    
    [OpenShare shareToWeibo:msg Success:^(OSMessage *message) {
        NSLog(@"分享到微博成功=%@",message);
    } Fail:^(OSMessage *message, NSError *error) {
        NSLog(@"分享到微博失败----error=%@",error);
    }];
}


- (IBAction)weixinShare:(UIButton *)sender {
}

//分享到qq朋友圈
- (IBAction)QQShare:(UIButton *)sender {
    OSMessage *msg = [self shareMessage];
    [OpenShare shareToQQFriends:msg Success:^(OSMessage *message) {
        NSLog(@"分享到QQ朋友圈成功---msg=%@",message);
    } Fail:^(OSMessage *message, NSError *error) {
        NSLog(@"分享到QQ朋友圈失败---error=%@",error);
    }];
}


- (IBAction)QQZoneShare:(UIButton *)sender {
    
    OSMessage *msg = [self shareMessage];
    
    [OpenShare shareToQQZone:msg Success:^(OSMessage *message) {
        NSLog(@"分享到QQ空间成功---msg=%@",message);
    } Fail:^(OSMessage *message, NSError *error) {
        NSLog(@"分享到QQ空间失败---error=%@",error);
    }];
    
}


/*********************** openShare实现第三方登陆 ******************************/


- (IBAction)weibo:(UIButton *)sender {
    
    [OpenShare WeiboAuth:@"all" redirectURI:@"https://www.jianshu.com/" Success:^(NSDictionary *message) {
       NSLog(@"微博登录成功:\n%@",message);
    } Fail:^(NSDictionary *message, NSError *error) {
        NSLog(@"微博登录失败:\n%@\n%@",message,error);
    }];
}

- (IBAction)weixin:(UIButton *)sender {
    /*微信需要收费才能获取到appkey等，所以这里没有列出代码*/
}
- (IBAction)qq:(UIButton *)sender {
    [OpenShare QQAuth:@"all" Success:^(NSDictionary *message) {
        NSLog(@"QQ登录成功:\n%@",message);
    } Fail:^(NSDictionary *message, NSError *error) {
        NSLog(@"QQ登录失败:\n%@\n%@",message,error);
    }];
}

@end
